$(function () {
    getOrgChartList();
    $('.orgchart-top a').click(function () {
        quickGoClick(this);
    });
   /*$("#full_screen").toggle(function () {
       alert(1);
       parent.getIframeFullScreen();
       $(this).innerText = "还原";
   },function () {
       alert(2);
       parent.cancelIframeFullScreen();
       $(this).innerText = "全屏";
   });*/
});
function quickGoClick(dom) {
    if(dom.id == "process_model"){
        alert(dom.innerText);
    }else if(dom.id == "grid_model"){
        alert(dom.innerText);
    }else if(dom.id == "project_file"){
        alert(dom.innerText);
    }else if(dom.id == "full_screen"){
        if($(dom).attr('screen_value') == 0){
            $(dom).attr('screen_value',1);
            parent.getIframeFullScreen();
            $(dom).find('span').text("还原");
        }else if($(dom).attr('screen_value') == 1){
            $(dom).attr('screen_value',0);
            parent.cancelIframeFullScreen();
            $(dom).find('span').text("全屏");
        }

    }
}
function getNode(data, id) {
    var _node;
    if ($.isArray(data)) {
        for (var i in data) {
            if (data[i].id == id) {
                console.log(data[i]);
                _node = data[i];
                break;
            } else {
                _node = getNode(data[i].children, id);
            }
        }
    } else {
        if (data.id == id) {
            console.log(data);
            _node = data;
        } else {
            _node = getNode(data.children, id);
        }
    }
    return _node instanceof Object ? _node.id : _node;
}

var orgChartNodes = null;

function getOrgChartList() {
    $.post(basePath + "/activiti/processManager/getOrgChartList", function (data) {
        orgChartNodes = data;
        $('#chart-container').orgchart({
            'data': data,
            'parentNodeSymbol': '',
            'createNode': function ($node, data) {
                $node.on('click', function (event) {
                    var _flag = false;
                    $('.popover-fixed-orgchart').each(function (index) {
                        if ($(this).prev().is($node)) {
                            _flag = true;
                            return true;
                        }
                        $(this).prev().popover('hide');
                    });
                    if (!_flag) {
                        $(this).popover({
                            template: '<div class="popover"><h3 class="popover-title"></h3><div class="popover-content"></div></div>',
                            html: 'true',
                            placement: 'right',
                            tipClass: 'popover-fixed-orgchart',
                            trigger: 'manual',
                            content: '<div><a id="triggerButton" onclick="updateRecord()">记录</a>&nbsp;<a>任命</a>&nbsp;<a href="javascript:void(0);" name="info">查看</a></div>'
                        });
                        $(this).popover('show');
                    } else {
                        $(this).popover('hide');
                    }
                });
                /*$(document).click(function(event) {
                    $(this).popover('hide');
                });*/
            }
        });
    });
}

function updateRecord(){
    var options = {
        name : "procInfoIframe",
        type : "iframe",
        url : basePath + "/activiti/processManager/getRecordInfo",
        backdrop : "static",
        moveable : "true",
        height : "700px",
        title : "流程记录"
    }
    var myModalTrigger = new $.zui.ModalTrigger(options);
    myModalTrigger.show();

}